package manager;

import java.awt.Color;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class ColorManager {

	protected static Properties config;
	protected FileInputStream inConfig;
	
	public ColorManager()
	{
		try {
			inConfig = new FileInputStream("appClientModule/config.properties");
			config = new Properties();
			config.load(inConfig);
			inConfig.close();
		} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
		// TODO Auto-generated catch block
			e.printStackTrace();
		}	
	}
	
	public Color[] getAllColors()
	{
		Color[] couleurs = new Color[Integer.parseInt(config.getProperty("nbColor"))];
		for (int i = 0; i < Integer.parseInt(config.getProperty("nbColor")); i++)
		{
			int r = Integer.parseInt(config.getProperty("color"+i).substring(0, 3));
			int g = Integer.parseInt(config.getProperty("color"+i).substring(3, 6));
			int b = Integer.parseInt(config.getProperty("color"+i).substring(6, 9));
			couleurs[i] = new Color(r,g,b);
		}
		return couleurs;
	}
	
	public Color getColor(int id)
	{
		int r = Integer.parseInt(config.getProperty("color").substring(0, 3));
		int g = Integer.parseInt(config.getProperty("color").substring(3, 6));
		int b = Integer.parseInt(config.getProperty("color").substring(6, 9));
		if (id == -1) return new Color(r,g,b);
		else return new Color(Integer.parseInt(config.getProperty("color"+id).substring(0, 3)),Integer.parseInt(config.getProperty("color"+id).substring(3, 6)),Integer.parseInt(config.getProperty("color"+id).substring(6, 9)));
	}
	
	public Integer[] getAllIds()
	{
		Integer[] ids = new Integer[Integer.parseInt(config.getProperty("nbColor"))];
		for (int i = 0; i < Integer.parseInt(config.getProperty("nbColor")); i++)
		{
			ids[i] = new Integer(i);
		}
		return ids;
	}
	
	public Color getColorBlack()
	{
		int r = Integer.parseInt(config.getProperty("colorBlack").substring(0, 3));
		int g = Integer.parseInt(config.getProperty("colorBlack").substring(3, 6));
		int b = Integer.parseInt(config.getProperty("colorBlack").substring(6, 9));
		return new Color(r,g,b);
	}
	
	public Color getColorWhite()
	{
		int r = Integer.parseInt(config.getProperty("colorWhite").substring(0, 3));
		int g = Integer.parseInt(config.getProperty("colorWhite").substring(3, 6));
		int b = Integer.parseInt(config.getProperty("colorWhite").substring(6, 9));
		return new Color(r,g,b);
	}
}
